var commonObj = {
    baseUrl: "http://47.242.237.113:3000/yuedu",
    beforeRun(project) {
        if (!androidObj) {
            toast("androidObj不存在")
            return false
        } else if (!androidObj[project]) {
            // toast(androidObj.num+"不执行"+project)
            return false
        } else {
            // toast(androidObj.num+"执行"+project)
            return true
        }
    },
    findClick(type, path) {
        var selector = null
        if (type == "id") {
            selector = id(path)
        } else if (type == "text") {
            selector = text(path)
        } else if (type == "clz") {
            selector = clz(path)
        }
        if (selector) {
            var result = click(selector);
            logd("====点击"+ path + result)
        }
    },
    getWaitTime(h, m, s) {
        if (!s) {
            s = 0
        }
        let res = 0
        res = new Date().setHours(h, m, s) - new Date().getTime()
        if (res < 0) {
            res = res + 24 * 60 * 60 * 1000
        }
        return res
    },
    autoStart(timeList) {
        // 获取当前时间的步骤
        let step = this.getStep(timeList);
        console.log("=====方法", timeList[step].method);
        timeList[step].method();
        if (step + 1 <= timeList.length) {
            //lockScreen();
            sleep(this.getWaitTime(timeList[step + 1].h, timeList[step + 1].m));
            this.autoStart(timeList);
        } else {
            toast("脚本执行完毕");
        }
    },
    getStep(timeList) {
        let step = -1;
        for (var i = 0; i < timeList.length; i++) {
            // var time = new Date().setHours(timeList[i].h) - (new Date().getMinutes() - timeList[i].m) * 60 * 1000 - (new Date().getSeconds() - (timeList[i].s || 0)) * 1000;
            var time = new Date().setHours(timeList[i].h) - (new Date().getMinutes() - timeList[i].m) * 60 * 1000 - new Date().getSeconds() * 1000;
            var now = new Date().getTime();
            if (now < time) {
                step = i - 1;
                break;
            }
        }
        return step
    },
    cycleShowToast() {
        toast("提示")
        sleep(5000)
        this.cycleShowToast()
    }
}
module.exports = commonObj